
#pragma once
#include "Character_define.h"
#include "goodlinklist.h"
#include <d3dx9.h>
#include <d3dx9mesh.h>
#include "IFile.h"
#include <TextureItem.h>

class CMeshNodeBase : public CModelRCBase
{
public:
	enum {_SER_D3D = 0,_SER_MEM};
	CMeshNodeBase() : m_pTexture(NULL), m_pD3DMesh(NULL),m_iSerialType(_SER_D3D),m_uMeshFVFSize(0)
	 {
	 }
	 virtual ~CMeshNodeBase()
	 {
	 }

	 inline LPDIRECT3DTEXTURE9 GetD3DTexture()
	 {
		 if (m_pTexture)
		 {
			 return m_pTexture->getTexture();
		 }
		 else
		 {
			 return NULL;
		 }
	 }


	 const D3DXVECTOR3& GetMin() const
	 {
		 return m_vecMin;
	 }

	 const D3DXVECTOR3& GetMax() const
	 {
		 return m_vecMax;
	 }


	 virtual void Serial(CIArchive& ar);
protected:
	 virtual void SerialD3D(CIArchive& ar) = 0;
	 virtual void SerialMem(CIArchive& ar) = 0;//to data transform from old;
	
	 virtual void SerialBase(CIArchive& ar);



	virtual void Term() = 0;

protected:	
	uint32 m_uVertexCount;
	uint32 m_uFaceCount;
	uint32 m_uMeshFVFSize;

	D3DXVECTOR3 m_vecMin;
	D3DXVECTOR3 m_vecMax;

	TextureItem*  m_pTexture;
	LPD3DXMESH m_pD3DMesh;


protected://for character logic
	int    m_iSerialType;	

};
class CMeshNodeInstance : public CGLLNode
{
public:
	CMeshNodeInstance(const int& iTppe,const int& iIndex = 0) : m_iType(iTppe),m_iIndex(iIndex)
	{
	}

	const int& GetType() const
	{
		return m_iType;
	};
	const int& GetIndex() const
	{
		return m_iIndex;
	}

protected:
	int    m_iType;
	int    m_iIndex;
};